package com.itlaobing.dao;

import com.itlaobing.entity.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Classname CustomerService
 * @Description JpaRepository<实体类类型，主键类型>：用来完成基本CRUD操作
 *               JpaSpecificationExecutor<实体类类型>：用于复杂查询（分页等查询操作）
 * @Date 2020/4/20 15:04
 * @Author by Administrator
 * @Version v1.0
 */
public interface CustomerDao extends JpaRepository<Customer,Long>, JpaSpecificationExecutor<Customer> {

    /**
     *  @Query 使用jpql的方式查询。
     */
    @Query(value="from Customer")
    public List<Customer> findAllCustomer();

    /**
     * @Query 使用jpql的方式查询。?1代表参数的占位符，其中1对应方法中的参数索引
     */
    @Query(value="from Customer where custName = ?1")
    public Customer findByCustName(String custName);

    @Query(value="update Customer set custName = ?1 where custId = ?2")
    @Modifying
    @Transactional //事务
    public void updateCustomer(String custName,Long custId);


    /**
     * nativeQuery : 使用本地sql的方式查询
     */
    @Query(value="select * from cust_customer",nativeQuery=true)
    public List<Customer> findSql();


}
